Skip to content

Reject escaping captures that cannot use closure storage - #676

Open
jogibear9988 wants to merge 1 commit into
dadhi:masterfrom
jogibear9988:fix/reject-unrepresentable-captures-20261114
Open

jogibear9988 wants to merge 1 commit into
dadhi:masterfrom
jogibear9988:fix/reject-unrepresentable-captures-20261114

Conversation

@jogibear9988

Copy link
Copy Markdown
Contributor

Reject escaping managed-reference, pointer and byref-like captures during collection instead of attempting to put them into closure storage. Ordinary inline access to an enclosing ref parameter remains supported.

Tests cover ref captures on all runtimes and Span captures on modern .NET, strict/throwing compilation modes, and supported inline ref access. No runtime delegate is produced for the rejected trees.

Validation

Full Release solution build and Standard/LightExpression native runners pass for net8.0, net10.0 and net472. net8.0: 690 TestX and 1744 legacy cases; net10.0: 690 TestX and 1745 legacy cases; net472: 669 TestX and 1610 legacy cases.

Measurements

FEC on master da14580f10fd19ae2361a8e91cfad4b2dfec182a → this change 9a53a7e28988168faeac1682e0d52d3f3e322662. Windows ARM64; .NET 8.0.28 and 10.0.9; SDK 10.0.301.

Trees, API conversions and invocation adapters are built before measurement. Compilation includes delegate creation; runtime measures the compiled delegate through the same adapter. Both sides are FEC: “System trees” names the expression API, not the System compiler.

Two opposite-load-order process rounds; seven alternating paired samples per round; medians of 14 samples, 100 ms calibration target. Verified task-local runtimes; tiered compilation disabled; each process pinned to one logical CPU. Allocations use GC.GetAllocatedBytesForCurrentThread. Slower observations are retained. Timing variation, including unchanged IL controls, prevents a blanket speedup or no-regression claim.

Runtime / API Workload Compile μs, master → patch Compile B/op Runtime ns, master → patch Runtime B/op
net10.0 / LightExpression delegate_invoke 29.710 → 21.560 1000.0 17.704 → 16.619 0.0
net10.0 / LightExpression nested_lambda 56.208 → 42.416 2048.1 11.898 → 12.087 0.0
net10.0 / LightExpression ref_call 19.147 → 14.644 928.0 11.267 → 9.652 0.0
net10.0 / LightExpression scalar_add 22.655 → 24.346 872.0 11.639 → 13.138 0.0
net10.0 / System trees delegate_invoke 27.329 → 40.709 1000.0 18.976 → 20.089 0.0
net10.0 / System trees nested_lambda 45.078 → 48.254 2048.2 11.815 → 13.226 0.0
net10.0 / System trees ref_call 34.395 → 30.360 928.0 10.853 → 6.865 0.0
net10.0 / System trees scalar_add 13.780 → 23.738 872.1 10.232 → 10.726 0.0
net8.0 / LightExpression delegate_invoke 21.618 → 19.278 1000.0 14.343 → 15.670 0.0
net8.0 / LightExpression nested_lambda 31.003 → 26.968 2048.0 12.068 → 8.804 0.0
net8.0 / LightExpression ref_call 17.370 → 10.253 928.0 9.052 → 7.639 0.0
net8.0 / LightExpression scalar_add 14.787 → 11.416 872.0 9.455 → 9.582 0.0
net8.0 / System trees delegate_invoke 35.994 → 36.089 1000.0 18.653 → 15.234 0.0
net8.0 / System trees nested_lambda 29.984 → 38.132 2048.1 11.688 → 8.477 0.0
net8.0 / System trees ref_call 22.527 → 16.780 928.0 9.133 → 10.302 0.0
net8.0 / System trees scalar_add 17.186 → 16.199 872.0 8.163 → 10.487 0.0

Shared-workload emitted IL is unchanged.

Allocation changes: none beyond measurement rounding in these shared workloads.

The affected invalid captures intentionally produce no runtime delegate; no affected runtime speed is claimed. The table measures supported controls.

Reject escaping managed-reference, pointer and byref-like captures during collection instead of attempting to put them into closure storage. Ordinary inline access to an enclosing ref parameter remains supported.

Tests cover ref captures on all runtimes and Span captures on modern .NET, strict/throwing compilation modes, and supported inline ref access. No runtime delegate is produced for the rejected trees.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant